package com.neusoft.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/{from}")
public class UserController {
	
	/*
	 * controller方法中的形参, 用于接收前端的入参
	 */
	
	@RequestMapping("/b")
	public void method1(HttpServletRequest request , HttpServletResponse response,@PathVariable("from") String from) throws ServletException, IOException{
		System.out.println(from);
		request.getRequestDispatcher("/"+from+"/login.jsp").forward(request, response);
	}
	
	@RequestMapping("/method2")
	public ModelAndView method2(){
		System.out.println("method2");
		ModelAndView mav = new ModelAndView();
		mav.setViewName("/index.jsp");
		return mav;
	}
	
	@RequestMapping("/method3")
	public String method3(){
		System.out.println("method3");
		return "/index.jsp";
	}
	
	/**
	 * 返回json字符串
	 * @return
	 */
	@RequestMapping("/method4")
	@ResponseBody
	public String method4(){
		return "{\"mess\" :\" hello\"}";
	}
	
	
}
